const formatTime = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}

const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : '0' + n
}

function GradetoGpa(grade){
  if(grade>=90)
    return 4.0;
  else if (grade >= 85 && grade < 90)
    return 3.7;
  else if (grade >= 82 && grade < 85)
    return 3.3;
  else if (grade >= 78 && grade < 82)
    return 3.0;
  else if (grade >= 75 && grade < 78)
    return 2.7;
  else if (grade >= 72 && grade < 75)
    return 2.3;
  else if (grade >= 68 && grade < 72)
    return 2.0;
  else if (grade >= 64 && grade < 68)
    return 1.5;
  else if (grade >= 60 && grade < 64)
    return 1.0;
  else if (grade <60)
    return 0.0;
}

module.exports = {
  formatTime: formatTime,
  GradetoGpa: GradetoGpa
}
